<template>
	<layout>
		<div class="wrapper">
			<van-form @submit="onSubmit" v-show="formDataVisible">
				<van-field
					v-model.trim="formData.linkMan"
					name="姓名"
					label="姓名"
					clearable
					placeholder="请输入联系人姓名"
					required
					:rules="[{ required: true, message: '请填写姓名' }]"
				/>
				<van-field
					v-model.trim="formData.linkPhone"
					name="手机号"
					label="手机号"
					clearable
					placeholder="请输入联系人手机号"
					type="tel"
					required
					:rules="[{ required: true, message: '请填写手机号' },{pattern:/^\d{11}$/,message:'手机号格式错误'}]"
				/>
				<van-field
					v-model.trim="formData.userNum"
					name="检验人数"
					label="检验人数"
					clearable
					type="digit"
					placeholder="请输入检验人数"
					@change="changeNum"
					required
					:rules="[{ required: true, message: '请填写检验人数' }]"
				/>
				<van-field
					name="上门时间"
					v-model="formData.applyTime"
					readonly
					clickable
					label="上门时间"
					placeholder="请选择上门时间"
					@click="showDatePicker = true"
					required
					:rules="[{ required: true, message: '请选择上门时间' }]"
				/>
				<span class="businessHoursShow" v-show="businessHoursShow">营业时间:{{ businessHours }}</span>
				<van-field
				    name="收样省市"
					:value="cityName"
					readonly
					clickable
					label="收样省市"
					placeholder="请选择收样省市"
					@click="showCityPicker = true"
					required
					:rules="[{ required: true, message: '请选择收样省市' }]"
				/>
				<van-field
					name="收样区域"
					v-model="areaName"
					readonly
					clickable
					label="收样区域"
					placeholder="请选择收样区域"
					@click="showAreaPicker = true"
					required
					:rules="[{ required: true, message: '请选择收样区域' }]"
				/>
                <van-field
				    name="详细地址"
                    v-model="formData.address"
                    rows="2"
                    autosize
                    label="详细地址"
                    type="textarea"
                    maxlength="50"
                    placeholder="请输入详细地址"
                    show-word-limit
					required
					:rules="[{ required: true, message: '请输入详细地址' }]"
                />
                <van-field
					name="留言"
                    v-model="formData.remark"
                    rows="2"
                    autosize
                    label="留言"
                    type="textarea"
                    maxlength="50"
                    placeholder="输入您的留言或备注"
                    show-word-limit
                />
                <span class="tips">具体事项等待工作人员联系，请保持手机畅通！</span>
                <div class="check-box">
                    <van-checkbox v-model="checked" shape="square"></van-checkbox>
                    <span style="margin-left:6px">
                        我已阅读并同意
                        <span style="color:#1487F2;text-decoration: underline;" @click="clickCheckBox">核酸检测知情同意书<span style="color:red">*</span></span>
                    </span>
                </div>
                <div class="money-box">
                    <span class="money-box-left">预计价格:</span>
                    <span class="money-box-right" v-show="priceBoxVisible">{{price}} 元 /人 - 总计：{{itemPrice?itemPrice:''}}元</span>
                </div>
				<div class="btn">
					<van-button round block type="info" native-type="submit" :disibled="submitVisible">提 交</van-button>
				</div>

			</van-form>
			<div class="qrcode-container" v-show="!formDataVisible">
				<div class="qrcode-wrapper">
					<div ref="qrcode">

					</div>
					<div class="title">
						{{qrcodeTitle}}
					</div>
				</div>

				<div class="qrcodeInfo">
					<van-cell-group>
						<van-cell title="预约编号：" :value="applyId+'号'" />
						<van-cell title="联系人：" :value="formData.linkMan" />
						<van-cell title="联系电话：" :value="formData.linkPhone" />
						<van-cell title="采样时间：" :value="formData.applyTime" />
						<van-cell title="采样地址：" :value="this.addressInfo" />
					</van-cell-group>
				</div>
			</div>
		</div>

		<van-popup v-model="showDatePicker" round position="bottom">
			<van-datetime-picker
				@change="changeFn()"
				@confirm="confirmFn()"
				@cancel="cancelFn()"
				v-model="currentDate"
				type="datetime"
				title="选择完整时间"
				:min-date="minDate"
				:max-date="maxDate"
				:formatter="formatter"
			/>
		</van-popup>

		<van-popup v-model="showCityPicker" round position="bottom">
			<van-picker
				title="选择省市"
				show-toolbar
				:columns="cityColumns"
				@confirm="onCityConfirm"
				@cancel="onCityCancel"
			/>
		</van-popup>

		<van-popup v-model="showAreaPicker" round position="bottom">
			<van-picker
				title="选择区域"
				show-toolbar
				:columns="areaColumns"
				@confirm="onAreaConfirm"
				@cancel="onAreaCancel"
			/>
		</van-popup>
	</layout>
</template>

<script>
// 这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
// 例如：import 《组件名称》 from '《组件路径》';
import nucleicApi from '@/api/nucleic.js'
import QRcode from "qrcodejs2"
export default {
	name:"nucleicVisit",
	// import引入的组件需要注入到对象中才能使用
	components: {},
	data() {
		// 这里存放数据
		return {
			hospitalId: '',
			openId: '',
			officeId: '',
			doctorId: '',
			// 上门时间
			businessHoursShow: true,
			businessHours: '',
			// 省名称
			provinceName: '',
			// 城市名称
			cityName: '',
			// 区域名称
			areaName: '',
			// 是否开通付款
			isPay: '',
			formData: {
				linkMan: '',
				linkPhone: '',
				userNum: '',
				applyTime: '',
				cityCode: '',
				areaCode: '',
				address: '',
				remark: ''
			},
			//表单数据与二维码的显示隐藏
			formDataVisible:true,
			// 时间弹框
			showDatePicker: false,
			currentDate: new Date(),
			changeDate: new Date(),
			// 可选时间区间
			minDate: new Date(2020, 0, 1),
			maxDate: new Date(2025, 10, 1),
            // 城市弹框
			showAreaPicker: false,
            // 区域弹框
			showCityPicker: false,
			// 城市列表
			cityColumns: [],
			// 区域列表
			areaColumns: [],
            // 价格模板
            hsPriceStr:null,
			// 价格
			price:"",
			// 价格盒子显示隐藏
			priceBoxVisible:true,
            // 复选框
            checked:false,
			// 提交框显示隐藏
			submitVisible:false,
			// 二维码标题
			qrcodeTitle:"",
			// 预约编号
			applyId:"",
		}
	},
	// 监听属性 类似于data概念
	computed: {
		itemPrice(){
			return this.formData.userNum*this.price
		},
		// 合并的详细地址
		addressInfo(){
			return this.provinceName+this.cityName+this.formData.address
		}
	},
	// 监控data中的数据变化
	watch: {},
	// 方法集合
	methods: {
        // 点击同意书
        clickCheckBox(){
			// 跳转到用户协议通知书
			this.checked = true;
			this.$router.push({path:'/nucleicAgreement',query: {}})

        },
		// 数量改变
		changeNum(){
			if(this.formData.areaCode){
				this.changeArea();
			}

		},
		// 确认-城市选择
		onCityConfirm(value, index) {
			this.cityName = value
			this.showCityPicker = false
		},
		// 取消-城市选择
		onCityCancel() {
			this.showCityPicker = false
		},
		// 确认-区域选择(改变区域)
		onAreaConfirm(value) {

			if(this.formData.userNum==0){
				this.$toast({
					type:"fail",
					message:"请先选择本次检验人数！"
				})
				return
			}else{
				this.areaName = value
				this.showAreaPicker = false

			}
			this.changeArea()


		},
		// 取消-区域选择
		onAreaCancel() {
			this.showAreaPicker = false
		},
		// 区域改变
		changeArea(){
			let hsPriceData
			let price = 0
			if(!this.hsPriceStr){
					if(this.doctorId){
						let params = {
							doctorId: this.doctorId
						}
						nucleicApi.getHsModelPrice(params)
							.then(res=>{
								if(res.status==0){
									this.hsPriceStr = res.data
								}else{
									this.$toast({
										type:"fail",
										message:"操作异常，请退出重进"
									})
									return
								}
							})
					}else{
						if(this.officeId){
							let params = {
								officeId: this.officeId
							}
							nucleicApi.getHsModelPrice(params)
								.then(res=>{
									if(res.status==0){
										this.hsPriceStr = res.data
									}else{
										this.$toast({
											type:"fail",
											message:"操作异常，请退出重进"
										})
										return
									}
								})
						}else{
							let params = {
								hospitalId: this.hospitalId
							}
							nucleicApi.getHsModelPrice(params)
								.then(res=>{
									if(res.status==0){
										this.hsPriceStr = res.data
									}else{
										this.$toast({
											type:"fail",
											message:"操作异常，请退出重进"
										})
										return
									}
								})
						}
					}

			}else{
				hsPriceData = JSON.parse(this.hsPriceStr);
			}
			if(this.formData.cityCode == 2){
				// 重庆
				this.priceBoxVisible = true
				if (hsPriceData){
					hsPriceData.nuclePriceList.forEach((obj,index)=>{
						if (obj.peopleMin <= this.formData.userNum && this.formData.userNum <= obj.peopleMax){
							price = obj.price;
						}
					});
				}else{
					if(this.formData.userNum == 1){
						price = 188;
					}else if(this.formData.userNum == 2){
						price = 128;
					}else if( 3 <= this.formData.userNum  && this.formData.userNum <= 5 ){
						price = 98;
					}else if( 6 <= this.formData.userNum && this.formData.userNum <= 8 ){
						price = 78;
					}else if( 9 <= this.formData.userNum && this.formData.userNum <= 10 ){
						price = 68;
					}else if( this.formData.userNum >= 11 ){
						price = 58;
					}
				}
			}else if(this.formData.cityCode == 4){
				// 选择其他
				price = 0;
				this.priceBoxVisible = true
			}else if(this.formData.cityCode == 3){
				//  保定
				if (hsPriceData){
					hsPriceData.nuclePriceList.forEach((obj,index)=>{
						if (obj.peopleMin <= this.formData.userNum && this.formData.userNum <= obj.peopleMax){
							price = obj.price;
						}
					});
				}else{
					if(this.formData.userNum == 1){
						price = 188;
					}else if(this.formData.userNum == 2){
						price = 128;
					}else if( 3 <= this.formData.userNum  && this.formData.userNum <= 5 ){
						price = 98;
					}else if( 6 <= this.formData.userNum && this.formData.userNum <= 8 ){
						price = 78;
					}else if( 9 <= this.formData.userNum && this.formData.userNum <= 10 ){
						price = 68;
					}else if( this.formData.userNum >= 11 ){
						price = 58;
					}
				}
			}else if(this.formData.cityCode == 5){
				//  北京
				if (hsPriceData){
					hsPriceData.nuclePriceList.forEach((obj,index)=>{
						if (obj.peopleMin <= this.formData.userNum && this.formData.userNum <= obj.peopleMax){
							price = obj.price;
						}
					});
				}else{
					if(this.formData.userNum == 1){
						price = 128;
					}else if(this.formData.userNum == 2){
						price = 98;
					}else if( 3 <= this.formData.userNum  && this.formData.userNum <= 5 ){
						price = 75;
					}else if( 6 <= this.formData.userNum && this.formData.userNum <= 8 ){
						price = 65;
					}else if( 9 <= this.formData.userNum && this.formData.userNum <= 10 ){
						price = 60;
					}else if( this.formData.userNum >= 11 ){
						price = 55;
					}
				}
			}else if(this.formData.cityCode == 8){
				//  贵阳
				if (hsPriceData){
					hsPriceData.nuclePriceList.forEach((obj,index)=>{
						if (obj.peopleMin <= this.formData.userNum && this.formData.userNum <= obj.peopleMax){
							price = obj.price;
						}
					});
				}else{
					if(this.formData.userNum == 1){
						price = 128;
					}else if(this.formData.userNum == 2){
						price = 98;
					}else if( 3 <= this.formData.userNum  && this.formData.userNum <= 5 ){
						price = 75;
					}else if( 6 <= this.formData.userNum && this.formData.userNum <= 8 ){
						price = 65;
					}else if( 9 <= this.formData.userNum && this.formData.userNum <= 10 ){
						price = 50;
					}else if( this.formData.userNum >= 11 ){
						price = 45;
					}
				}
			}else{
				//  长沙、怀化、南昌、抚州
				if (hsPriceData){
					hsPriceData.nuclePriceList.forEach(obj=>{
						if (obj.peopleMin <= this.formData.userNum && this.formData.userNum <= obj.peopleMax){
							price = obj.price;
						}
					});
				}else{
					if(this.formData.userNum == 1){
						price = 100;
					}else if(this.formData.userNum == 2){
						price = 75;
					}else if( 3 <= this.formData.userNum  && this.formData.userNum <= 5 ){
						price = 55;
					}else if( 6 <= this.formData.userNum && this.formData.userNum <= 8 ){
						price = 50;
					}else if( 9 <= this.formData.userNum && this.formData.userNum <= 10 ){
						price = 45;
					}else if( this.formData.userNum >= 11 ){
						price = 40;
					}
				}
			}

			// this.price = price
			// if(this.formData.cityCode == cityEle){
				// 医院与地址对应时
				this.price = price
			// }else{
			// 	// itemPrice = 0;
			// 	// $("#price").val(itemPrice);
			// 	// document.getElementById("price_box").innerHTML="价格待商议";
			// 	this.priceBoxVisible = false
			// }
		},

		// 选择时间格式化
		formatter(type, val) {
			if (type === 'year') {
				return `${val}年`
			} else if (type === 'month') {
				return `${val}月`
			} else if (type === 'day') {
				return `${val}日`
			}
			return val
		},
		// 日期值变化时触发
		changeFn() {
			this.changeDate = this.currentDate // Tue Sep 08 2020 00:00:00 GMT+0800 (中国标准时间)
		},
		// 日期确定按钮
		confirmFn() {
			this.formData.applyTime = this.$Utils.formatDatetime(this.currentDate)
			this.showDatePicker = false
		},
		// 日期取消按钮
		cancelFn() {
			this.showDatePicker = false
		},
		// 时间格式化
		// timeFormat(time) {
		// 	let year = time.getFullYear()
		// 	let month = time.getMonth() + 1
		// 	let day = time.getDate()
		// 	let hours = time.getHours()
		// 	let minu = time.getMinutes()
		// 	return year + '年' + month + '月' + day + '日 ' + hours + ':' + minu
		// },
		// 判断来源是否有科室
		ishospital(state) {
			if (state && state.indexOf(',') > -1) {
				let params = state.split(',')
				this.hospitalId = params[0]
				this.officeId = params[1]
				if (params.length > 2) {
					this.doctorId = params[2]
				}
			} else {
				this.hospitalId = state
			}
            // 获取价格模板
            this.isMoneyMB();
            // 根据医院获取城市区域列表
			this.gethospitalMsg(this.hospitalId)
		},
		/**
		 * 根据医院的Id 获取到医院信息
		 * 1. 控制城市数组的展示
		 * 2. 控制付款码的展示
		 */
		gethospitalMsg(hospitalId) {
			let params = {
				hospitalId: hospitalId
			}
			var _this = this
			nucleicApi
				.getHospitalInfo(params)
				.then(res => {
					if (res.status == 0) {
						if (res.data) {
							let datas = res.data
							let isHsPay = Number(datas.isHsPay)
							_this.provinceName = datas.provinceName
							_this.cityName = datas.cityName
							_this.isPay = isHsPay
							_this.showCity(datas.cityName)
							// if(isHsPay == 1){
							//     let btn = document.getElementById("addReportButton");
							//     btn.innerHTML = "立即支付"
							// }
							// 北京需要显示营业时间
							let businessHours = datas.businessHours
							if (businessHours) {
								_this.businessHours = businessHours
								_this.businessHoursShow = true
							} else {
								_this.businessHoursShow = false
							}
						} else {
							_this.$dialog.alert({
								title:"提示",
								message:"请退出页面，重新进入，否者此次申请无效！"
							}).then(res=>{
								window.close();
								WeixinJSBridge.call('closeWindow');
							})
							return
						}
					}else{

					}
				})
				.catch(err => console.log('getHospitalInfo', err))
		},
		// 城市过滤
		showCity(val) {
			if (val == '长沙市') {
				this.formData.cityCode = 0
				this.cityColumns = ['长沙市']
			} else if (val == '怀化市') {
				this.formData.cityCode = 1
				this.cityColumns = ['怀化市']
			} else if (val == '重庆市') {
				this.formData.cityCode = 2
				this.cityColumns = ['重庆市']
			} else if (val == '保定市') {
				this.formData.cityCode = 3
				this.cityColumns = ['保定市']
			} else if (val == '北京市') {
				this.formData.cityCode = 5
				this.cityColumns = ['北京市']
			} else if (val == '南昌市') {
				this.formData.cityCode = 6
				this.cityColumns = ['南昌市']
			} else if (val == '抚州市') {
				this.formData.cityCode = 7
				this.cityColumns = ['抚州市']
			} else if (val == '贵阳市') {
				this.formData.cityCode = 8
				this.cityColumns = ['贵阳市']
			} else {
				this.formData.cityCode = 4
			}
			this.changeCity(this.formData.cityCode)
		},
		// 地区过滤
		changeCity(onCity) {
			if (onCity == 0) {
				this.areaColumns = ['岳麓区', '芙蓉区', '天心区', '开福区', '雨花区', '望城区', '长沙县'] // 长沙
			} else if (onCity == 1) {
				this.areaColumns = ['鹤城区', '麻阳县', '辰溪县'] // 怀化
			} else if (onCity == 2) {
				this.areaColumns = ['江北区', '沙坪坝区', '大渡口区', '九龙坡区', '南岸区'] // 重庆
			} else if (onCity == 3) {
				this.areaColumns = ['定兴县', '高碑店市', '白沟新城', '雄安新区'] // 保定
			} else if (onCity == 5) {
				this.areaColumns = ['大兴区', '通州区', '海淀区', '丰台区', '朝阳区'] // 北京
			} else if (onCity == 6) {
				this.areaColumns = ['东湖区', '西湖区', '青云谱区', '青山湖区', '新建区', '红谷滩区'] // 南昌
			} else if (onCity == 7) {
				this.areaColumns = ['临川区', '东乡区'] // 抚州
			} else if (onCity == 8) {
				this.areaColumns = ['南明区', '云岩区', '花溪区', '乌当区', '白云区', '观山湖区'] // 贵阳
			} else if (onCity == 4) {
				this.areaColumns = ['其他'] // 其他
			}
		},
		// 判断是否绑定海报价格模板，如果绑定，使用海报模板的价格区间
		isMoneyMB() {
			var _this = this
			let doctorId = _this.doctorId

			if (doctorId) {
				// 医生模板
				let params = {
					doctorId: doctorId
				}
				nucleicApi
					.getHsModelPrice(params)
					.then(res => {
						if (res.status == 0) {
							if (res.data) {
								// 核酸价格模板集合
                                _this.hsPriceStr = JSON.stringify(res.data)
							} else {
								_this.$dialog.alert({
									title:"提示",
									message:"医生模板操作异常，请退出重进"
								}).then(res=>{
									window.close();
									WeixinJSBridge.call('closeWindow');
								})
								return
							}
						}
					})
					.catch(err => {
						_this.$dialog.alert({
							title:"错误",
							message:err
						})
					})
			} else {

				let officeId = _this.officeId
                // 科室模板
				if (officeId) {
					// 科室模板
					let params = {
						officeId: officeId
					}
					nucleicApi.getHsModelPrice(params)
						.then(res => {
							if (res.status == 0) {
								if (res.data) {
                                    console.log('科室价格模板',res.data)
									// 核酸价格模板集合
									_this.hsPriceStr = JSON.stringify(res.data)
								} else {
									_this.$dialog.alert({
										title:"提示",
										message:"科室模板操作异常，请退出重进"
									}).then(res=>{
										window.close();
										WeixinJSBridge.call('closeWindow');
									})
									return
								}
							}
						})
						.catch(err => {
							this.$dialog.alert({
								title:"错误",
								message:err
							})
						})
				} else {
                    //console.log('isMb3')
					//  医院模板
					let params = {
						hospitalId: _this.hospitalId
					}
					nucleicApi
						.getHsModelPrice(params)
						.then(res => {
							if (res.status == 0) {
								if (res.data) {
                                    console.log('医院价格模板',res.data)
									// 核酸价格模板集合
									_this.hsPriceStr = JSON.stringify(res.data)
								} else {
									this.$dialog.alert({
										title:"提示",
										message:"医院模板操作异常，请退出重进"
									}).then(res=>{
										window.close();
										WeixinJSBridge.call('closeWindow');
									})
									return
								}
							}
						})
						.catch(err => {
							this.$dialog.alert({
								title:"错误",
								message:err
							})
						})
				}
			}
		},
		getOpenId(code) {
			let params = {
				code: code||false
			}
			nucleicApi
				.getOpenId(params)
				.then(res => {
					if (res.status == 0) {
						if (res.data) {
							this.openId = res.data
						} else {
							this.$dialog.alert({
								title:"提示",
								message:"请退出页面，重新进入，否者此次申请无效！"
							}).then(res=>{
								window.close();
								WeixinJSBridge.call('closeWindow');
							})
						}
					}else{
						this.$dialog.alert({
							title:"提示",
							message:res.msg
						})
					}
				})
				.catch(err => console.log('openId获取失败', err))
		},
		// 提交
		onSubmit() {
			if(!this.checked){
				this.$toast({
					type:"fail",
					message:"未确认知情书"
				})
				return
			}
			this.formData.linkMan = this.formData.linkMan.replace(/\s+/,"")
			this.formData.address = this.formData.address.replace(/\s+/,"")

			this.submitVisible = true
			let params = {
				linkMan: this.formData.linkMan,
				linkPhone: this.formData.linkPhone,
				hospitalId: Number(this.hospitalId),
				institutionId: 88,
				userNum: Number(this.formData.userNum),
				openId: this.openId,
				applyTime: this.formData.applyTime,
				itemName: "新型冠状病毒核酸检测",
				itemPrice: Number(this.itemPrice),
				address: this.addressInfo,
				remark: this.formData.remark
			}
			if(this.officeId) params.officeId = Number(this.officeId)
			if(this.doctorId) params.doctorId = Number(this.doctorId)
			nucleicApi.addApply(params)
				.then(res=>{
					if(res.status == 0){
						this.applyId = res.data
						if(this.isPay==0){
							// 没有开通核酸支付 进入填写信息的二维码  -- 医院支付方式为：月结
							this.showQrCode();
						}else if(this.isPay==1){
							// 开通了微信支付 开启支付 -- 医院支付方式为：预约时支付
							this.wxToPay();;
						}else{
							this.showQrCode();
						}

					}else{
						this.$dialog.alert({
							title:"提示",
							message:res.msg
						})
					}
					this.submitVisible = false

				})
				.catch(err=>{
					this.$dialog.alert({
						title:"错误",
						message:err
					})
					this.submitVisible = false
				})
		},
		// 二维码
		showQrCode() {
			this.formDataVisible = false
			// 弹出一串码 转换为二维码
			let defaultContent = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxe7229f039bfe873b&redirect_uri=http%3A%2F%2Fh5.kanglailab.com%2FnucleicMessage&response_type=code&scope=snsapi_base&state='+this.applyId; // 路径
			// let defaultContent = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxe7229f039bfe873b&redirect_uri=http%3A%2F%2Fh5.kanglailab.com%2FnucleicPage%2Fnucleic_message.html&response_type=code&scope=snsapi_base&state='+123123; // 路径
			new QRcode(this.$refs.qrcode,{
				text:defaultContent,
				width:220,
				height:220,
				correctLevel: 3
			});
			this.qrcodeTitle = 	"请截图保存后，扫描二维码 填写个人信息！"

    	},
		// 微信支付
		wxToPay(){
			let _this = this
			let params = {
				applyId: Number(this.applyId),
				actualPay: Number(this.itemPrice),
				payType: 1,
        	}
			nucleicApi.wxPay(params)
				.then(res=>{
					if (res.status == 0){
                    let payConfig = res.data;
                    WeixinJSBridge.invoke(
                        'getBrandWCPayRequest', {
                            "appId":payConfig.appId,     //公众号ID，由商户传入
                            "timeStamp":payConfig.timeStamp,         //时间戳，自1970年以来的秒数
                            "nonceStr":payConfig.nonceStr, //随机串
                            "package":payConfig.package,
                            "signType":payConfig.signType,         //微信签名方式
                            "paySign":payConfig.paySign //微信签名
                        },
                        function(res){
                            //alert(res.err_msg);
                            if(res.err_msg == "get_brand_wcpay_request:ok"){
                                // 使用以上方式判断前端返回,微信团队郑重提示：
                                //res.err_msg将在用户支付成功后返回ok，但并不保证它绝对可靠。
                                _this.showPaySuccessMsg();
                                // 成功了 就显示二维码
                            }else if(res.err_msg == "get_brand_wcpay_request:cancel"){
                                // 提示用户取消了二维码支付
                                //deleteApply(infoData.applyId);
								_this.$dialog.alert({
									title:"提示",
									message:"用户取消了支付"
								})
                                return
                            }else if(res.err_msg == "get_brand_wcpay_request:fail"){
                                // 提示支付失败
                                //deleteApply(infoData.applyId);
								_this.$dialog.alert({
									title:"提示",
									message:"支付失败"
								})
                            }
                        });

					}else{
						_this.$dialog.alert({
							title:"提示",
							message:res.msg
						})
						return;
					}

				})

		},
		// 支付成功
		showPaySuccessMsg() {
			this.qrcodeTitle="支付成功，工作人员稍后会联系您，若半小时之内未收到短信或者电话 您可拨打客服热线 400-1512-686";
			this.formDataVisible = false
		}
		//
	},
	// 生命周期 - 创建完成（可以访问当前this实例）
	created() {},
	// 生命周期 - 挂载完成（可以访问DOM元素）
	mounted() {
		let query = this.$route.query
		let code = query.code;
		if(code){
		    // 获取openID
		    this.getOpenId(code);
		}

		let state = query.state
		if (state) {
			// 这里先需要解码
			this.ishospital(decodeURIComponent(state))
		}else{
			this.$dialog.alert({
				title:"提示",
				message:"请退出页面，重新进入，否者此次申请无效！"
			}).then(res=>{
				window.close();
				WeixinJSBridge.call('closeWindow');
			})

		}
		// this.showQrCode()
	},
}
</script>
<style lang="less" scoped>
.wrapper {
    background: white;
	box-sizing: border-box;
	overflow: hidden;
    border-radius: 10px;
	width: 93%;
	margin: auto;
	box-shadow: 0 0 10px 0 rgba(0, 0, 0, 10%);
	.businessHoursShow {
	color: red;
	font-size: 13px;
	position: relative;
	left: 20px;
	top: -6px;
	}
	.tips{
		color: #ABABAB;
		font-size: 12px;
		padding: 10px 15px;
	}
	.check-box{
		margin-top: 5px;
		display: flex;
		color: #ABABAB !important;
		font-size: 13px;
		padding: 10px 15px;
		border-bottom: 1px solid #f8f8f8;
	}
	.money-box{
		font-size: 16px;
		padding: 10px 15px;
	}
	.money-box-left{
		font-weight: bold;
	}
	.money-box-right{
		margin-left: 20px;

	}
	.btn{
		margin: 20px;
	}
	.qrcode-container{
		background-color: white;
		margin: 10px 0;
		border-radius: 10px;
		padding: 20px 0;
		overflow: hidden;
		text-align: center;
		.qrcode-wrapper{
			width: 220px;
			// height: 170px;
			margin: 0 auto;
			.qrcode{
				width: 220px;
			}
			&::v-deep{
				img{
					width: 100%;
				}
			}
			.title{
				color: red;
				margin: 10px 0;
				font-size: 18px;
			}
		}
		.qrcodeInfo{
			text-align: start;
		}
	}
}

</style>
